package com.smart.seckilldemo.utils;


import org.apache.commons.codec.digest.DigestUtils;

/**
 * MD5 加密
 */
public class MD5Utils {
    //加密盐
    public static final String SALT="1a2b3c4d";

    public static String md5(String src){
        return DigestUtils.md5Hex(src);
    }

    //首次加密
    public static String inputPassword(String inputPass){
        String str=SALT.charAt(0)+SALT.charAt(2)+inputPass+SALT.charAt(5);
        return md5(str);
    }

    //第二次加密
    public static String formPassToDBPassword(String foramen,String salt){
        String str=salt.charAt(0)+salt.charAt(2)+foramen+salt.charAt(5);
        return md5(str);
    }
    // 不用盐封装加密
    public static String inputPassToDBPassword(String inputPass){
        String fromPass =inputPassword(inputPass);
        String dbPass = formPassToDBPassword(fromPass,SALT);
        return dbPass;
    }
    //封装盐加密
    public static String inputPassToDBPasswordSlat(String inputPass,String slat){
        String fromPass =inputPassword(inputPass);
        String dbPass = formPassToDBPassword(fromPass,slat);
        return dbPass;
    }

    public static void main(String[] args) {
        System.out.println(inputPassToDBPasswordSlat("123", "asdijuhasguidg"));

    }

}
